
import plugin from '../../../../lib/plugins/plugin.js';
import Work from '../service/work.js';
import { pm, getPlayerByE } from './main.js';



export class LNERobot extends plugin {
	playerManager: import("d:/QQRobot/Yunzai/Miao-Yunzai/plugins/LNERobot/ts/model/player/player_manager").default;
	constructor() {
		super({
			name: '机器人',
			dsc: '机器人',
			event: 'message',
			priority: 5,
			rule: [
				{
					/** 命令正则匹配 */
					reg: '^(开始打工|打工开始|上班)$',
					/** 执行方法 */
					fnc: 'startWork'
				},
				{
					/** 命令正则匹配 */
					reg: '^(结束打工|下班)$',
					/** 执行方法 */
					fnc: 'stopWork'
				},
				{
					/** 命令正则匹配 */
					reg: '^打工(菜单)?$',
					/** 执行方法 */
					fnc: 'work'
				},
			]
		});

		this.playerManager = pm;
	}

	async work(e) {
		let work = new Work();
		super.reply(
			`打工菜单\n` +
			`- 开始打工\n` +
			`- 结束打工`
		);
	}

	async startWork(e) {
		let work = new Work();
		let player = await getPlayerByE(e);
		let { msg } = await work.start(player);
		await this.playerManager.savePlayer(player);
		super.reply(msg);
	}

	async stopWork(e) {
		let work = new Work();
		let player = await getPlayerByE(e);
		let { msg } = await work.stop(player);
		await this.playerManager.savePlayer(player);
		super.reply(msg);
	}

}
